package com.mysterymall.Controller;

import com.mysterymall.Common.Comp.LocalCache;
import com.mysterymall.Common.Comp.Log;
import com.mysterymall.Common.Utils.Result;
import com.mysterymall.Service.BlindBoxGroupService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName com.mysterymall.Controller
 * @Description
 * @Author HuangWX
 * @Time 2023/11/18  09:23
 */
@RestController
@RequestMapping("/blindBoxGroup")
public class BlindBoxGroupCont {


    private final BlindBoxGroupService blindBoxGroupService;


    /**
     * 构造器注入
     *
     * @param blindBoxGroupService 盲盒分组服务
     */
    public BlindBoxGroupCont(BlindBoxGroupService blindBoxGroupService) {
        this.blindBoxGroupService = blindBoxGroupService;
    }

    /**
     * 查询盲盒分组
     * @return Result
     */
    @GetMapping("/getShowBoxGroup")
    @Log
    // 参数中加入请求头
    public Result getShowBoxGroup(HttpServletRequest request) {

        return blindBoxGroupService.getShowBoxGroup(request);

    }


    /**
     * 查询盲盒分组中的商品 (用户) -- 气泡效果
     *
     * @param groupId 盲盒分组id
     * @return Result
     */
    @GetMapping("/getBoxGroupGoods")
    @Log
    public Result getBoxGroupGoods(@RequestParam("groupId") String groupId) {
        return blindBoxGroupService.getBoxGroupGoods(groupId);
    }


    /**
     * 获取通知
     * @return Result
     */
    @GetMapping("/getBoxGroupGoodsNotice")
    @Log
    public Result getBoxGroupGoodsNotice() {

        Object o = LocalCache.CACHE.get("BOX_GROUP_GOODS_NOTICE");

        if (o != null) {
            List<String> NoticeList = (List<String>) o;
            return Result.success("message.querySuccess", NoticeList);
        } else {
            return Result.success("message.querySuccess", null);
        }
    }


    /**
     * 查询盲盒详细信息 (用户)
     * @param blindBoxGroupId 盲盒分组id
     * @return Result
     */
    @GetMapping("/getShowBlindBoxGroupMonocle")
    @Log
    public Result getShowBlindBoxGroupMonocle(@RequestParam("blindBoxGroupId") String blindBoxGroupId,HttpServletRequest request) {
        return blindBoxGroupService.getShowBlindBoxGroupMonocle(blindBoxGroupId,request);
    }


    /**
     * 获取我的订单盲盒
     * @param orderId 订单ID
     * @param request 请求头
     * @return Result
     */
    @GetMapping("/getMyBoxList")
    @Log
    public Result getMyBoxList(@RequestParam("orderId") String orderId,HttpServletRequest request) {
        return blindBoxGroupService.getMyBoxList(orderId,request);
    }


    @GetMapping("/getMyBox")
    @Log
    public Result getMyBox(@RequestParam("current")Integer current , @RequestParam("pageSize")Integer pageSize, HttpServletRequest request) {
        return blindBoxGroupService.getMyBox(current,pageSize,request);
    }


    /**
     * 查询盲盒分组中的商品 (管理员)
     * @param blindBoxGroupId 盲盒分组id
     * @return Result
     */
    @GetMapping("/getBlindBoxGroupGoods")
    @Log
    public Result getBlindBoxGroupGoods(@RequestParam("id") String blindBoxGroupId, HttpServletRequest request) {
        return blindBoxGroupService.getBlindBoxGroupGoods(blindBoxGroupId, request);
    }

    /**
     * 查询我的盲盒分组
     * @return Result
     */
    @GetMapping("/getMyBlindBoxGroup")
    @Log
    public Result getMyBlindBoxGroup() {
        return blindBoxGroupService.getMyBlindBoxGroup();
    }

    /**
     * 开启盲盒分组--- 试玩
     * @param number 盲盒数量
     * @return Result
     */
    @GetMapping("/getTestGoods")
    @Log
    public Result getTestPlay(@RequestParam("id")String id ,@RequestParam("number")Integer number,HttpServletRequest request) {
        return blindBoxGroupService.openBlindBoxTest(id,number,request);
    }

    /**
     * 开启盲盒分组--- 真实
     * @param number 盲盒数量
     * @return Result
     */
    @GetMapping("/getGoods")
    @Log
    public Result getPlay(@RequestParam("id")String id ,@RequestParam("number")Integer number,HttpServletRequest request) {
        return blindBoxGroupService.openBlindBox(id,number,request);
    }


}
